# -*- coding: utf-8 -*-
# @Time : 2021/9/17 17:23
# @Author : 伟哥
# @Email : xw@gmail.com
# @File : MRYX_WD_003.py.py
# @Project : mryx_test
from time import sleep
from appium import webdriver
from appium.webdriver.common.mobileby import MobileBy as By


desired_capabilities={
    "platformName":"Android",
    "deviceName":"127.0.0.1:62001",
    "platformVersion":"7.1.2",
    "appPackage": "cn.missfresh.application",
    "appActivity":"cn.missfresh.module.main.view.MainActivity",
    "noReset":"True"
}
driver=webdriver.Remote("http://localhost:4723/wd/hub",desired_capabilities)
driver.implicitly_wait(60)
try:
    my_locator=(By.XPATH,'//android.widget.TextView[@resource-id=\"cn.missfresh.application:id/mineTab\"]')
    address_locator=(By.XPATH,'//android.widget.ImageView[@content-desc=\"收货地址\"]')
    add_locator=(By.XPATH,"//android.view.View[@content-desc=\"新增收货地址\"]")
    name_locator=(By.ANDROID_UIAUTOMATOR,'new UiSelector().text("请填写收货人的姓名")')
    phone_locator=(By.ANDROID_UIAUTOMATOR,'new UiSelector().text("请填写收货人手机号")')
    select_locator=(By.ANDROID_UIAUTOMATOR,'new UiSelector().text("点击选择收货地址")')
    house_locator=(By.ANDROID_UIAUTOMATOR,'new UiSelector().text("详细地址，例如：3号楼二单元105")')
    lable_locator=(By.XPATH,'//android.view.View[@content-desc=\"公司\"]')
    save_locator=(By.XPATH,'//android.view.View[@content-desc=\"保存收货信息\"]')
    delete_locator=(By.XPATH,'//android.view.View[@content-desc=\"删除收货信息\"]')
    #点击我的
    sleep(5)
    driver.find_element(*my_locator).click()
    #点击收货地址
    sleep(1)
    driver.find_element(*address_locator).click()
    #点击新增地址
    sleep(1)
    driver.find_element(*add_locator).click()
    #输入收获人姓名
    sleep(1)
    name_element=driver.find_element(*name_locator)
    name_element.click()
    name_element.send_keys("行编辑")
    #输入收货人手机号
    sleep(1)
    phone_element=driver.find_element(*phone_locator)
    phone_element.click()
    phone_element.send_keys("13356789011")
    #选择收货地址
    sleep(1)
    driver.find_element(*select_locator).click()
    sleep(3)
    driver.tap([(314,930)],100)
    #输入门牌号
    sleep(1)
    house_element=driver.find_element(*house_locator)
    house_element.click()
    house_element.send_keys("规划进口美食")
    #点击标签【公司】
    sleep(1)
    driver.find_element(*lable_locator).click()
    #点击保存
    sleep(1)
    driver.find_element(*save_locator).click()
    #点击编辑
    sleep(2)
    driver.tap([(680,137)])
    #点击删除地址
    sleep(1)
    driver.find_element(*delete_locator).click()
    #断言元素

except Exception:
    raise
finally:
    sleep(5)
    driver.quit()